<template>
  <div class="folderbox">
    <!-- 我的收藏夹 -->
    <div class="foldertile">我的书签</div>
    <!-- 主体区域 -->
    <div class="foldermain">
      <div class="folertitleboxs">
        <div class="casesearch">
          <a-input-search
            :style="{ width: '249px' }"
            placeholder="请输入名称"
            v-model="caseName"
          />
          <div class="casesearchbt" @click="fetchData">搜索</div>
          <div class="casesearchbt1" @click="rest">重置</div>
        </div>
      </div>
      <!-- 内容展示区域 -->

      <!-- 图谱展示区域 -->
      <div class="tplistman" v-if="tabid == 1">
        <div
          class="tplistitembox"
          v-for="items in rendata"
          :key="items"
          @click="gosq(items)"
        >
          <div class="tplistitemimg">
            <!-- 收藏标识 -->

            <div class="favoritebox" @click.stop="favoritefn(items)">
              <img src="@/assets/images/sqq.png" alt="" />
            </div>

            <img :src="`${base + items.url}`" alt="" />
          </div>
          <div class="tplistitemname" :title="items.medicineAtlasName">{{
            items.medicineAtlasName
          }}</div>
          <div
            class="tplistitemnames"
            v-for="item in rendatas"
            v-show="item.medicineAtlasId == items.medicineAtlasId"
            >加权：<span>{{ item.typeNum }}</span
            >，解剖面：<span>{{ item.classificationNum }}</span></div
          >
          <!-- <div class="mask">
                <div class="" @click="addbs(items.medicineAtlasId, items)">
                  <img src="@/assets/images/zxicon.png" alt="" />
                  自学模式</div
                > 
              </div>-->
        </div>
      </div>

      <div class="pagbox"
        ><a-pagination
          :total="total"
          :current="current"
          :page-size="pageSize"
          show-total
          show-jumper
          show-page-size
          @change="nextpage"
          @page-size-change="pageSizefn"
          :page-size-options="[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12]"
        />
      </div>
    </div>

    <a-modal v-model:visible="visible" @ok="handleOk">
      <template #title> 提示 </template>
      <div style="text-align: center; font-size: 16px">确定取消书签？</div>
    </a-modal>
  </div>
</template>

<script lang="ts" setup>
  import { ref, watch } from 'vue';
  import {
    bookMarkList,
    favoriteAdd,
    bookMarkDel,
    medicineList,
  } from '@/api/case';
  import { useRouter } from 'vue-router';
  import { useRoute } from 'vue-router';
  import useUser from '@/hooks/user';
  import { storeToRefs } from 'pinia';
  import { Message, Modal, TreeNodeData } from '@arco-design/web-vue';
  import { useUserStore } from '@/store';
  const router = useRouter();
  const route = useRoute();
  const userStore = useUserStore();
  const userdata = storeToRefs(userStore);
  const studentdata = ref(userdata);
  const caseName = ref('');
  const tabid = ref(1);
  const rendata = ref();
  const pageSize = ref(10);
  const current = ref(1);
  const total = ref();
  const base = ref((window as any).config.VUE_APP_IMG_API);

  const fetchData = () => {
    bookMarkList({
      pageSize: pageSize.value,
      pageNum: current.value,
      medicineAtlasName: caseName.value,
      studentId: studentdata.value.studentId,
    }).then((res: any) => {
      if (res.code == 200) {
        rendata.value = res.data.list;
        total.value = res.data.total;
        current.value = res.data.pageNum;
        pageSize.value = res.data.pageSize;
      }
    });
  };
  fetchData();
  const rest = () => {
    current.value = 1;
    pageSize.value = 6;
    caseName.value = '';
    fetchData();
  };

  const nextpage = (i) => {
    current.value = i;
    fetchData();
  };
  const pageSizefn = (i) => {
    pageSize.value = i;
    fetchData();
  };

  const visible = ref(false);
  //
  const handleOk = () => {
    bookMarkDel({
      bookMarkIds: bookMarkId.value,
    }).then((res: any) => {
      if (res.code == 200) {
        Message.success('取消收藏');
        fetchData();
      }
    });
  };
  const bookMarkId = ref();
  const favoritefn = (item) => {
    visible.value = true;
    console.log('item', item);
    bookMarkId.value = item.bookMarkId;

    //
  };

  const goitem = (item: any) => {
    console.log('sss', item);

    router.push({
      name: 'case',
      query: {
        // caseTypeId: caseTypeId.value,
        caseName: item.caseAtlasName,
        caseTypeName: '病例收藏',
        caseId: item.caseAtlasId,
        favoriteFolderId: item.favoriteFolderId,
      },
    });
  };
  const rendatas = ref();
  const medicinefn = () => {
    medicineList().then((res: any) => {
      //   console.log('查询解剖数量', res.data);
      rendatas.value = res.data;
    });
  };
  medicinefn();

  // 走图谱闲情
  const gosq = (item) => {
    localStorage.setItem('dcomid', item.medicineAtlasImgId);
    router.push({
      name: 'dashboardindex',
      query: {
        medicineAtlasId: item.medicineAtlasId,
        medicineAtlasName: item.medicineAtlasName,
        atlasTypeName: item.atlasTypeName,
      },
    });
  };
</script>

<style scoped>
  .casesearch {
    font-size: 14px;
    color: #666666;
    display: flex;
    align-items: center;
  }
  .casesearchbt {
    font-size: 12px;
    color: #ffffff;
    width: 60px;
    height: 34px;
    line-height: 34px;
    text-align: center;
    background: linear-gradient(180deg, #748191 0%, #242834 100%);
    border-radius: 4px 4px 4px 4px;
    margin: 0px 5px;
    cursor: pointer;
  }
  .casesearchbt1 {
    text-align: center;
    line-height: 34px;
    font-size: 12px;
    color: #ffffff;
    width: 60px;
    height: 34px;
    background: linear-gradient(180deg, #b3c1d2 0%, #748191 100%);
    border-radius: 4px 4px 4px 4px;
    cursor: pointer;
  }
  .folderbox {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
  }
  .foldertile {
    font-size: 20px;
    font-weight: 800;
    margin: 10px 0;
  }
  .foldermain {
    width: 1486px;
    height: 766px;
    background: #e8ebee;
    border-radius: 10px 10px 10px 10px;
    border: 1px solid #a3b0c1;
    padding: 15px;
    display: flex;
    flex-direction: column;
  }
  .folertitleboxs {
    height: 56px;
    width: 1426px;
    border-radius: 0px 0px 0px 0px;

    margin: 0 auto;
    display: flex;
    justify-content: flex-end;
  }
  .folericon img {
    width: 12px;
    height: 12px;
    margin-right: 10px;
  }
  .folericon {
    font-size: 16px;
    color: rgba(153, 153, 153, 1);
    width: 130px;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0px 2px;
    position: relative;
  }
  .folericons {
    color: #3c4459;
  }
  .tabbs {
    width: 50px;
    height: 3px;
    border-radius: 0px 0px 0px 0px;
    background-color: #3c4459;
    position: absolute;
    bottom: -6.5px;
  }
  .folderitembox {
    background: red;
    display: flex;
    flex-direction: column;
  }
  .pagbox {
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* new */
  .casemain {
    display: flex;
    flex-wrap: wrap; /* 允许换行 */

    width: 100%;
    overflow-y: auto;
    gap: 10px; /* 可选，设置间距 */
  }

  .casemain {
    display: flex;
    flex-wrap: wrap; /* 允许换行 */
    justify-content: flex-start; /* 从左到右排列 */
    gap: 30px; /* 控制间距 */
    height: 600px;
    width: 100%;
    overflow-y: auto;
    padding: 36px;
  }
  .casemainitem {
    width: 440px;
    height: 246px;
    background: #ffffff;
    border-radius: 10px;
    display: flex;
    padding: 10px;
    cursor: pointer;
  }
  .pagbox {
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .casemainitemimg {
    width: 180px;
    height: 204px;
    border-radius: 5px;
    overflow: hidden;
    margin: 10px;
  }
  .casemainitemimg img {
    width: 180px;
    height: 204px;
    border-radius: 5px;
    overflow: hidden;
  }
  .caseitemdes {
    display: flex;
    flex-direction: column;
    padding: 15px 0;
  }
  .caseitemtitle {
    font-size: 18px;
    color: #333333;
    width: 180px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
  .caseitemdestext {
    width: 180px;
    font-size: 16px;
    color: #666666;
    height: 134px;
    margin: 10px 0;
  }
  .caseitemfa {
    font-size: 14px;
    color: #999999;
    display: flex;
    align-items: center;
    cursor: pointer;
  }
  .caseitemfa img {
    width: 20px;
    height: 20px;
  }
  /* new */
  /* new2 */
  .tplistitembox {
    cursor: pointer;
    flex: 0 0 250px;
    height: 246px;
    background: #f5f6fa;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }
  .tplistitemimg {
    width: 250px;
    height: 160px;
    overflow: hidden;
    position: relative;
  }
  .tplistitembox:hover .mask {
    opacity: 1;
  }
  .tplistitemimg img {
    width: 250px;
    height: 160px;
  }
  .tplistitemname {
    font-weight: bold;
    font-size: 18px;
    color: #333333;
    height: 50px;
    line-height: 50px;
    padding-left: 20px;
    width: 210px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  .tplistitemnames {
    font-weight: bold;
    font-size: 14px;
    color: #666666;
    height: 30px;
    line-height: 30px;
    padding-left: 20px;
    width: 210px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  .tplistitemnames span {
    color: #fd5c00;
  }
  .tpmainrightbox {
    position: relative;
    width: 403px;
    height: 820px;
    border-radius: 20px; /* 圆角半径 */
    margin-top: 20px;
    border: 1px solid #9db6d6;
    display: flex;
    flex-direction: column;
  }
  .tplistman {
    display: flex;
    flex-wrap: wrap; /* 允许换行 */
    justify-content: flex-start; /* 从左到右排列 */
    gap: 30px; /* 控制间距 */
    height: 600px;
    width: 100%;
    overflow-y: auto;
    padding: 36px;
  }
  .favoritebox {
    position: absolute;
    right: 10px;
    top: 10px;
  }
  .favoritebox img {
    width: 18px;
    height: 24px;
  }
</style>
